using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Bludz
{
    /// <summary>
    /// Represents one object in the game.
    /// </summary>
    class Entity
    {

        private Dictionary<String, Var> vars;

        public String name;

        public Entity()
        {
            vars = new Dictionary<String, Var>();
        }

        public void log(String s)
        {
            LogServer.get().log(name, s);
        }

        private Var igetVar(String varName)
        {
            if (hasVar(varName))
                return vars[varName];
            else
            {
                Var var = new Var();
                vars[varName] = var;
                return var;
            }
        }

        /// <summary>
        /// Does the entity have a var with this name?
        /// </summary>
        /// <param name="varName">The var's name</param>
        /// <returns>whether it's there</returns>
        public bool hasVar(String varName) {
            return vars.ContainsKey(varName);
        }

        /// <summary>
        /// Set a var of type T
        /// </summary>
        /// <typeparam name="T">The type of the var</typeparam>
        /// <param name="varName">The name of the var</param>
        /// <param name="val">The value of the var</param>
        public void setVar<T>(String varName, T val)
        {
            igetVar(varName).set<T>(val);
        }

        public void defaultVar<T>(String varName, T val)
        {
            if (!hasVar(varName))
                setVar<T>(varName, val);
        }

        /// <summary>
        /// Get a var of type T
        /// </summary>
        /// <typeparam name="T">The type of the var</typeparam>
        /// <param name="varName">The name of the var</param>
        /// <returns>The value of the var</returns>
        public T getVar<T>(String varName)
        {
            return igetVar(varName).get<T>();
        }
    }
}
